package com.kc.web.controller.business;

import com.kc.business.domain.BizGoodsSku;
import com.kc.business.service.IBizGoodsSkuService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品规格管理controller
 */
@RestController
@RequestMapping("/business/goodsSku")
public class BizGoodsSkuController extends BaseController {
    @Autowired
    private IBizGoodsSkuService goodsSkuService;
    /**
     * 商品规格列表
     * @param bizGoodsSku
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:goodsSku:list')")
    @GetMapping("/list")
    public TableDataInfo getList(BizGoodsSku bizGoodsSku){
        startPage();
        return getDataTable(goodsSkuService.getList(bizGoodsSku));
    }
    /**
     * 商品规格新增
     * @param bizGoodsSku
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:goodsSku:add')")
    @Log(title = "商品规格管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizGoodsSku bizGoodsSku) {
        return toAjax(goodsSkuService.add(bizGoodsSku));
    }

    /**
     * 商品规格修改
     * @param bizGoodsSku
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:goodsSku:edit')")
    @Log(title = "商品规格管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizGoodsSku bizGoodsSku) {
        return toAjax(goodsSkuService.edit(bizGoodsSku));
    }
    /**
     * 商品规格删除
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:goodsSku:remove')")
    @Log(title = "商品规格管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id) {
        BizGoodsSku bizGoodsSku = new BizGoodsSku();
        bizGoodsSku.setId(id);
        bizGoodsSku.setIsDeleted(1);
        return toAjax(goodsSkuService.edit(bizGoodsSku));
    }



}
